<template>
  <div class="component-makeBudget">
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>基础价格表
          </p>
        </div>
        <div class="topright">
          <el-button type="info" @click="$router.go(0)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe662;</span>刷新
          </el-button>
        </div>
      </div>
    </div>
    <div class="component-listHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont">&#xe61e;</span>
            基础价格表
          </p>
          <div class="right">
            <el-button @click="edit">{{editBtn?'进行编辑':'取消编辑'}}</el-button>
            <el-button style="width:70px;" @click="commit">保存</el-button>
          </div>
        </div>
      </div>
    </div>
    <div class="budgets">
      <div class="component_btnGroup">
        <el-button-group>
          <el-button
            v-for="(item,index) in menuList"
            :key="index"
            @click="handleClick(index,item.constCode)"
            :style="chooseBtn==index?'color:#fff;background:#1abc9c;':'color:#666;background:#fff;'"
          >{{item.constName}}</el-button>
        </el-button-group>
      </div>
      <div class="dbTable">
        <!--<div class="budgetTable">
          <div class="tableTitle">甲方结算表</div>
          <table cellpadding="0" cellspacing="0" border="1">
            <tr>
              <th>工作项目名称</th>
              <th>单项费用（元）</th>
            </tr>
            <tr v-for="(item,index) in aLists" :key="index">
              <th>{{item.label}}</th>
              <td style="width:220px;padding:0;">
                <el-input-number style="width:219px;" :disabled="editBtn" v-model="item.value" :precision="2" :step="0.1" :min="0" controls-position="right" placeholder="请输入金额"></el-input-number>
              </td>
            </tr>
          </table>
        </div>-->
        <div class="budgetTable">
          <div class="tableTitle">施工队结算表</div>
          <table cellpadding="0" cellspacing="0" border="1">
            <tr>
              <th>工作项目名称</th>
              <th>单项费用（元）</th>
            </tr>
            <tr v-for="(item,index) in TLists" :key="index">
              <th>{{item.itemName}}</th>
              <td style="width:220px;padding:0;">
                <el-input-number v-if="isNaN(item.price)||item.price==''||item.price==undefined" style="width:219px;" :disabled="editBtn" v-model="item.price=0" :precision="2" :step="0.1" :min="0" controls-position="right" placeholder="请输入金额"></el-input-number>
                <el-input-number v-else style="width:219px;" :disabled="editBtn" v-model="item.price" :precision="2" :step="0.1" :min="0" controls-position="right" placeholder="请输入金额"></el-input-number>
              </td>
            </tr>
          </table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "contractList",
    data() {
      return {
        chooseBtn: 0,//按钮组的选中值
        aLists: [],
        TLists: [],
        editBtn: true,
        menuList:[],
        constId:'',
      };
    },
    created() {},
    mounted() {
      this.queryConst();
    },
    methods: {
      // 查询接口
      baseConfigSelect() {
        let that = this,
          suCb = res => {
            that.TLists = res.data.data;
          },
          erCb = function(res) {
            console.log(res);
          },
          req = {
            url: "/api/web/ptsp/selectLastSettlementPrice",
            methods: "post",
            data: {proType:that.constId||that.menuList[0].constCode},
            success: suCb,
            error: erCb
          };
        that.$https(req);
      },
      // 编辑按钮 事件处理函数
      edit(tab) {
        this.editBtn = !this.editBtn;
      },
      commit(tab) {
        if (!this.editBtn) {
          let that = this,
            suCb = res => {
              console.log(res);
              that.$msg('保存成功')
              that.editBtn = !that.editBtn;
              that.baseConfigSelect();
            },
            erCb = function(res) {
              console.log(res);
            },
            req = {
              url: "/api/web/ptsp/modifySettlementPrice",
              methods: "post",
              data: {
                priceList:that.TLists
              },
              success: suCb,
              error: erCb
            };
          that.$https(req);
        } else {
          this.$erMsg("先编辑，后保存！");
        }
      },
      //切换按钮
      handleClick(active,id) {
        this.chooseBtn = active;
        this.constId = id;
        this.baseConfigSelect();
      },
      //常量接口
      queryConst(){
        let that = this,
          suCb = res => {
            that.menuList = res.data.data;
            that.baseConfigSelect();
            console.log(res.data.data)
          },
          erCb = function(res) {
            console.log(res);
          },
          req = {
            url: "/api/web/sysConst/queryConst",
            methods: "post",
            data: {
              typeCode:'ProjectFixType'
            },
            success: suCb,
            error: erCb
          };
        that.$https(req);
      }
    }
  };
</script>

<style scoped>
  .component-listHeader .search-header {
    width: 1100px;
    box-sizing: border-box;
    border: 1px solid rgba(228, 228, 228, 1);
    border-bottom: none;
    background-color: rgba(255, 255, 255, 1);
    margin: 30px auto 0;
  }

  .component-listHeader .search-header .left-title {
    display: flex;
    justify-content: space-between;
    width: 100%;
    background-color: rgba(243, 243, 243, 1);
    height: 45px;
    box-sizing: border-box;
  }

  .component-listHeader .search-header .left-title .left-text {
    width: 20%;
    color: #666;
    line-height: 45px;
    font-family: "微软雅黑";
    font-weight: 400;
    font-size: 12px;
    text-align: left;
    margin: 0 0 0 30px;
  }

  .component-listHeader .search-header .right {
    width: 70%;
    display: flex;
    justify-content: flex-end;
    margin-right: 10px;
  }

  .component-listHeader .search-header .right button {
    padding: 0 15px;
    height: 30px;
    width: 110px;
    margin: 6px 5px;
    line-height: 30px;
    font-size: 14px;
    color: #1abc9c;
    background-color: #fff;
    border: 1px solid #ccc;
  }
  .el-form-item {
    width: 310px;
    margin-bottom: 20px !important;
  }
  .component-listHeader .search-header .right button:hover {
    background-color: #1abc9c;
    color: #fff;
  }
  .component-listHeader .search-header .right .right-select-margin {
    margin-top: 8px;
    margin-right: 8px;
  }
  /* 处理a链接 */
  a {
    text-decoration: none;
    color: #1abc9a;
  }
  a:hover {
    cursor: pointer;
  }

  .component-makeBudget .tabs-header {
    width: 1150px;
    box-sizing: border-box;
    margin: 0 auto 0;
  }

  .fl_container {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
  }
  .fl_container .fl_left {
    text-align: left;
  }
  .fl_container .fl_right {
    text-align: right;
  }

  /* 表格部分 */
  .budget {
    margin-top: 20px;
    width: 100%;
    overflow: hidden;
    background: #f8f8f8;
    height: 35px;
    line-height: 35px;
    font-size: 14px;
    border: 1px solid #e4e4e4;
    border-bottom: none;
    padding: 0 20px;
    box-sizing: border-box;
    font-size: 14px;
    color: #666;
  }
  .gcl .title {
    background: #f8f8f8;
    height: 35px;
    line-height: 35px;
    color: #666;
    padding: 0 20px;
    font-size: 14px;
    border: 1px solid #e4e4e4;
    border-bottom: none;
    text-align: left;
  }
  .budget .title {
    float: left;
  }
  .budget div:last-of-type {
    float: right;
  }
  .gcl .tabs {
    width: 1060px;
    margin: 20px;
    box-sizing: border-box;
  }

  .budgetTable table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    margin: 0 0 20px 0;
    padding: 0;
    border: none;
    font-size: 12px;
  }
  .budgetTable table td,
  th {
    height: 40px;
  }

  th {
    background-color: #f9fafc;
  }

  .gcl_footer {
    text-align: right;
    margin: 20px 0 0 0;
  }

  .gcl_footer .gcl_footer_bottom span {
    color: #1abc9c;
  }

  .gcl_footer .gcl_footer_bottom {
    margin-bottom: 10px;
    margin-right: 2px;
    font-size: 19px;
  }

  /* 双表格容器 */
  .dbTable {
    width: 1100px;
    margin: 0 auto;
    box-sizing: border-box;
    border: 1px solid #eee;
    border-top:none;
    display: flex;
    justify-content: space-around;
  }

  .dbTable .budgetTable {
    width: 500px;
  }

  .component-model .component-listHeader .search-header {
    width: 900px;
    box-sizing: border-box;
    border: 1px solid rgba(228, 228, 228, 1);
    background-color: rgba(255, 255, 255, 1);
    margin: 20px auto 0;
    border-bottom: 0;
  }

  .component-model .component-listHeader .search-header .left-title {
    display: flex;
    justify-content: space-between;
    width: 100%;
    background-color: rgba(243, 243, 243, 1);
    height: 45px;
    box-sizing: border-box;
  }

  .component-model .component-listHeader .search-header .left-title .left-text {
    width: 20%;
    color: #666;
    font-family: "微软雅黑";
    font-weight: 400;
    font-size: 12px;
    line-height: 45px;
    text-align: left;
    margin: 0 0 0 30px;
  }

  .component-model
  .component-listHeader
  .search-header
  .right
  .right-select-margin {
    margin-top: 6px;
    margin-right: 8px;
  }

  .component-model .table {
    width: 100%;
    margin: 0 auto;
  }

  .underTable {
    width: 100%;
    margin: 25px 0 0 15px;
    display: flex;
    justify-content: flex-start;
    align-items: baseline;
  }

  .tableTitle {
    text-align: center;
    margin: 15px auto;
  }
  .component_btnGroup {
    margin: 0 auto;
    padding: 20px;
    text-align: left;
    width: 1100px;
    box-sizing: border-box;
    border: 1px solid #eee;
    border-bottom: none;
  }
</style>
